/*
 * @Author: LIFM0623 1944099171@qq.com
 * @Date: 2024-01-11 15:16:44
 * @LastEditors: EyeSklear 1814580085@qq.com
 * @LastEditTime: 2024-05-16 15:44:16
 * @FilePath: \Scene_Back\src\app.module.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Module, MiddlewareConsumer } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './user/entities/user.entity';
import { PictureModule } from './picture/picture.module';
import { TextModule } from './text/text.module';
import { AudioModule } from './audio/audio.module';
import { EmailModule } from './email/email.module';
import { ConfigService, ConfigModule } from '@nestjs/config';
import { AuthModule } from './auth/auth.module';
import { MapEaseModule } from './map-ease/map-ease.module';
import { CameraRotateModule } from './camera-rotate/camera-rotate.module';
import { MarkerModule } from './marker/marker.module';
import { VideoModule } from './video/video.module';
import { CameraalongModule } from './cameraalong/cameraalong.module';
import { Cameraalong } from './cameraalong/entities/cameraalong.entity';
import { GeojsonModule } from './geojson/geojson.module';
import { ImagerasterModule } from './imageraster/imageraster.module';
import { DynamiclayerModule } from './dynamiclayer/dynamiclayer.module';
import { APP_GUARD } from '@nestjs/core';
import { JwtAuthGuard } from './common/guards/auth.guard';
import { GroupModule } from './group/group.module';
import { FileListModule } from './file-list/file-list.module';
import { PathListModule } from './path-list/path-list.module';
import { SceneListModule } from './scene-list/scene-list.module';
import { PathItemRelationalModule } from './path-item-relational/path-item-relational.module';
import { ScenePathRelationalModule } from './scene_path_relational/scene_path_relational.module';
import { SceneFileRelationalModule } from './scene_file_relational/scene_file_relational.module';
import { ScriptListModule } from './script-list/script-list.module';
import { ShareModule } from './share/share.module';
import { WinstonModule } from './winston/winston.module';
import { format, transports } from 'winston';
import { FolderModule } from './folder/folder.module';
import * as chalk from 'chalk';
// import { EventsGateway } from './EventGateway';
import { WebsocketModule } from './websocket/websocket.module';
import { PublicResourceModule } from './public_resource/public_resource.module';
import { SceneBondScriptModule } from './scene_bond_script/scene_bond_script.module';
import { GenerativeAiAchievementModule } from './generative-ai-achievement/generative-ai-achievement.module';
import { FilmListModule } from './film-list/film-list.module';
import { FilmPathRelationalModule } from './film_path_relational/film_path_relational.module';
import { FilmFileRelationalModule } from './film_file_relational/film_file_relational.module';

@Module({
  imports: [
    UserModule,
    PictureModule,
    // TypeOrmModule.forRoot({
    //   type: 'postgres',
    //   host: 'localhost',
    //   port: 5432,
    //   username: 'postgres',
    //   password: '123',
    //   database: 'scene_db',
    //   entities: [__dirname + '/**/*.entity{.ts,.js}'],
    //   synchronize: true,
    //   uuidExtension: 'pgcrypto',
    // }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => ({
        type: 'postgres', // 数据库类型
        autoLoadEntities: true, // 自动加载实体   （强烈推荐）
        host: configService.get('DB_HOST', 'localhost'), // 主机，默认为localhost
        port: configService.get<number>('DB_PORT', 5432), // 端口号
        username: configService.get('DB_USER', 'postgres'), // 用户名
        password: configService.get('DB_PASSWORD', '123'), // 密码
        database: configService.get('DB_DATABASE', 'scene_db'), //数据库名
        fileEnvPath: configService.get('FILE_PATH', process.env.FILE_PATH), //配置文件路径
        timezone: '+08:00', //服务器上配置的时区
        synchronize: true, //根据实体自动创建数据库表， 生产环境建议关闭
      }),
    }),
    TextModule,
    AudioModule,
    EmailModule,
    AuthModule,
    MapEaseModule,
    CameraRotateModule,
    MarkerModule,
    VideoModule,
    CameraalongModule,
    GeojsonModule,
    ImagerasterModule,
    DynamiclayerModule,
    GroupModule,
    FileListModule,
    PathListModule,
    SceneListModule,
    PathItemRelationalModule,
    ScenePathRelationalModule,
    SceneFileRelationalModule,
    ScriptListModule,
    ShareModule,
    WinstonModule.forRoot({
      level: 'debug',
      transports: [
        new transports.Console({
          format: format.combine(
            format.colorize(),
            format.printf(({ context, level, message, time }) => {
              const appStr = chalk.green(`[NEST]`);
              const contextStr = chalk.yellow(`[${context}]`);

              return `${appStr} ${time} ${level} ${contextStr} ${message} `;
            }),
          ),
        }),
        new transports.File({
          format: format.combine(format.timestamp(), format.json()),
          filename: 'ScenceEidtorLogger.log',
          dirname: 'log',
        }),
      ],
    }),
    FolderModule,
    WebsocketModule,
    PublicResourceModule,
    SceneBondScriptModule,
    GenerativeAiAchievementModule,
    FilmListModule,
    FilmPathRelationalModule,
    FilmFileRelationalModule,
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    }
  ],
})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {}
}
